﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

using System.Reflection;

namespace Milo.Framework
{
    public class FieldControl<TModel> : ModelControl<TModel>, IFieldControl<TModel>
    {

        #region constructors
		public FieldControl() { }
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldControl&lt;FieldType&gt;"/> class.
        /// <para>Initialises the control directly with the model object</para>
        /// </summary>
        /// <param name="model">The model.</param>
        public FieldControl(TModel model) : base(model) { }
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldControl&lt;FieldType&gt;"/> class.
        /// <para>Initialises the control directly with the model object as well as the Control name.
        /// This will act as a container name for any child controls</para>
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="model">The model.</param>
        public FieldControl(string name, TModel model) : base(name, model) { }

        #endregion

        #region IFieldControl<FieldType> Members

        public bool ReadOnly { get; set; }

        public void AttachExitAction<TController>(Expression<Func<TController, System.Web.Mvc.ActionResult>> action)
            where TController : class
        {
        }
        #endregion

        public override string ToString()
        {
			try
			{
				return Value.ToString();
			}
			catch (NullReferenceException)
			{
				return string.Empty;
			}
        }
    }
}
